package me.algo.array;

import java.util.LinkedHashMap;
import java.util.Objects;

/**
 * @author guozheng
 * @date 2024/4/17
 */
public class A4 {
    public static void main(String[] args) {

        int[] nums = {0};
        sortColors(nums);
        System.out.println(nums);
    }

    /**
     * 75. 颜色分类
     * @param nums
     */
    static public void sortColors(int[] nums) {
        if (Objects.isNull(nums)) {
            return;
        }
        LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer val = map.getOrDefault(nums[i], 0);
            map.put(nums[i], val + 1);
        }
        int start = 0;
        for (int i = 0, star = 0; i < 3 & start < nums.length; i++) {
            Integer size = map.get(i);
            if (Objects.isNull(size)) {
                continue;
            }
            while (size > 0) {
                size--;
                nums[star] = i;
                star++;
            }
        }
    }
}
